function changeindex() {
    window.location.href="/index2";
}
function add() {
    var cnName = $.trim($('#cnName').val());
    var enName = $.trim($('#enName').val());
    var phoneNumber = $.trim($('#phoneNumber').val());
    var idcardNumber = $.trim($('#idcardNumber').val());
    var userType = $.trim($('#userType').val());
    var createTime = $.trim($('#createTime').val());
    var createUser = $.trim($('#createUser').val());
    var limitedDays = $.trim($('#limitedDays').val());
    var reasons = $.trim($('#reasons').val());
    var description = $.trim($('#description').val());
    var otherInformation = $.trim($('#otherInformation').val());
    var form_data = $('#form_data').serialize();
    if(cnName==null||cnName==""||enName==null||enName==""||phoneNumber==null||phoneNumber==""||idcardNumber==null||idcardNumber==""){
        alert("输入参数错误");
        return
    }
    $.ajax(
        {
            url: "/chaincode/useradd",
            data: form_data,
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data.code == 1000) {
                    swal({
                        title:"新增成功",
                        type: "success",
                        text: "2秒后自动关闭。",
                        timer:2000
                    });
                    setTimeout("location.reload();",2000);
                    return;
                }else {
                    swal({
                        title:"新增失败",
                        type: "error",
                        text: "2秒后自动关闭。",
                        timer: 2000
                    });
                    setTimeout("location.reload();",2000);
                    return;
                }
            },
            error: function () {
                swal({
                    title:"未知错误",
                    type: "error",
                    text: "2秒后自动关闭。",
                    timer: 2000
                });
                setTimeout("location.reload();",2000);
            }
        });
}
function query() {
    var arg=$.trim($('#arg').val());
    var data = {"arg": arg};
    $.ajax({
        url: "/chaincode/userquery",
        type: "post",
        data: JSON.stringify(data),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (dat) {
            if (dat.code == 1000) {
                if(dat.data==""||dat.data==null){
                    swal({
                        title: "未查询到信息",
                        type: "error",
                        buttons: false,
                        timer: 1000
                    });
                } else if(dat.data.cnName==null||dat.data.cnName==""){
                        swal({
                            title: "未查询到信息",
                            type: "error",
                            buttons: false,
                            timer: 1000
                        });
                }else{
                    $('#cnName1').val(dat.data.cnName);
                    $('#enName1').val(dat.data.enName);
                    $('#phoneNumber1').val(dat.data.phoneNumber);
                    $('#idcardNumber1').val(dat.data.idcardNumber);
                    $('#userType1').val(dat.data.userType);
                    $('#createTime1').val(dat.data.createTime);
                    $('#createUser1').val(dat.data.createUser);
                    $('#limitedDays1').val(dat.data.limitedDays);
                    $('#reasons1').val(dat.data.reasons);
                    $('#description1').val(dat.data.description);
                    $('#otherInformation1').val(dat.data.otherInformation);
                    $('#queryBlackModal').modal('show');
                }

            } else {
                swal({
                    title: "查询失败",
                    type: "error",
                    buttons: false,
                    timer: 1000
                });
            }
        },
        error: function (returndata) {
            swal({
                title: "发生错误",
                type: "error",
                buttons: false,
                timer: 1000
            });
        }
    });

}

function remove() {
    var phoneNum=$.trim($('#phoneNumber1').val());
    var idNum=$.trim($('#idcardNumber1').val());
    var form_data = $('#form_data1').serialize();
    var data={"phoneNum":phoneNum,"idNum":idNum};
    $.ajax({
        url: "/chaincode/userdelete",
        type: "post",
        data: JSON.stringify(data),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (dat) {
            if (dat.code == 1000) {
                    swal({
                        title: "删除失信名单成功",
                        type: "success",
                        buttons: false,
                        timer: 1000
                    });
                setTimeout("location.reload();",1000);
            }
            else{
                swal({
                    title: "删除失败",
                    type: "error",
                    buttons: false,
                    timer: 1000
                });
                setTimeout("location.reload();",1000);
            }
        },
        error: function (returndata) {
            swal({
                title: "请求错误",
                type: "error",
                buttons: false,
                timer: 1000
            });
            setTimeout("location.reload();",1000);
        }
    });

}
